package com.sinoglobal.dumpling.service;

import android.app.IntentService;
import android.content.Intent;
import android.os.Environment;

import com.sinoglobal.dumping.base.Dumpling_SinoLogUtil;
import com.sinoglobal.dumping.util.Dumpling_FileUtils;

import java.io.File;
import java.io.IOException;

/**
 * Created by Administrator on 2016/3/9.
 */
public class Dumpling_CopyFileService extends IntentService {

    /**
     * Creates an IntentService.  Invoked by your subclass's constructor.
     *
     * @param name Used to name the worker thread, important only for debugging.
     */
    public Dumpling_CopyFileService() {
        super("CopyFileService");
    }

    @Override
    protected void onHandleIntent(Intent intent) {
        String action = intent.getStringExtra("action");
        if ("copyAPK".equals(action) && Environment.isExternalStorageEmulated()) {
            String outPath = Environment.getExternalStorageDirectory() + "/DynamicLoadHost";
            File directory = new File(outPath);
            File file=new File(directory,"pluginb-debug.zip");
            if (!directory.exists()) {
                directory.mkdir();
            }
            if (!file.exists()) {
                try {
                    Dumpling_FileUtils.copyAssets2SD(this, "pluginb-debug.zip", outPath + "/pluginb-debug.zip");
                } catch (IOException e) {
                    Dumpling_SinoLogUtil.e(e.getMessage());
                }
            }
        }
    }
}
